package com.xiaoyu.cloud.config;


import com.xiaoyu.cloud.core.config.WhitelistPathConfig;
import com.xiaoyu.cloud.interceptor.HeaderTransInterceptor;
import com.xiaoyu.common.core.constant.ComConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zgb
 * @desc ...
 * @date 2023-08-04 00:01:38
 */

@Configuration
public class HeaderTransInterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private WhitelistPathConfig whitelistPathConfig;
    @Autowired
    private HeaderTransInterceptor headerTransInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //表示要拦截
        String[] addPathPatterns = {
                ComConst.INTERCEPTOR_ANY_MATCH
        };
        //要排除的路径
        String excludedUris = String.join(",", whitelistPathConfig.getUrls());
        //用注解识别是否需要登录，而不是路径
        registry.addInterceptor(headerTransInterceptor).addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludedUris)
                .order(100);
    }


}

